import requests

BASE_URL = 'http://localhost:8080/api/product'

# Function to load the token from token.txt
def load_token():
    with open('token.txt', 'r') as file:
        return file.read().strip()

# Load the token
TOKEN = load_token()

# Function to create a new product
def create_product(developer_id, product_name):
    headers = {'Authorization': f'Bearer {TOKEN}'}
    response = requests.post(BASE_URL, params={'developer_id': developer_id, 'name': product_name}, headers=headers)

    print("code = " + str(response.status_code ))

    if response.status_code == 200:
        print('Product created successfully:', response.json())
    else:
        print('Failed to create product:', response.json())

# Function to get products by developer ID
def get_products(developer_id):
    headers = {'Authorization': f'Bearer {TOKEN}'}
    response = requests.get(BASE_URL, params={'developer_id': developer_id}, headers=headers)

    if response.status_code == 200:
        print('Products retrieved successfully:', response.json())
    else:
        print('Failed to retrieve products:', response.json())

# Example usage
if __name__ == '__main__':
    developer_id = 1  # Replace with a valid developer ID
    product_name = "TLD Redux (One month)"  # Replace with the desired product name

    # Create a new product
    create_product(developer_id, product_name)

    # Get products for the specified developer
    get_products(developer_id)